<?php

namespace App\Admin\Controllers;

use App\Http\Controllers\Controller;
use App\Models\Base\StatEvent;
use Encore\Admin\Controllers\ModelForm;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;

class EventController extends Controller
{
    use ModelForm;

    /**
     * Index interface.
     *
     * @return Content
     */
    public function index()
    {
        return Admin::content(function (Content $content) {
            $content->header(trans('game.player_related'));
            $content->description(trans('admin.list'));

            $content->body($this->grid());
        });
    }

    /**
     * Edit interface.
     *
     * @param $id
     *
     * @return Content
     */
    public function edit($id)
    {
        return Admin::content(function (Content $content) use ($id) {
            $content->header(trans('game.player_related'));
            $content->description(trans('admin.edit'));

            $content->body($this->form()->edit($id));
        });
    }

    /**
     * Create interface.
     *
     * @return Content
     */
    public function create()
    {
        return Admin::content(function (Content $content) {
            $content->header(trans('game.player_related'));
            $content->description(trans('game.new'));

            $content->body($this->form());
        });
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Admin::grid(StatEvent::class, function (Grid $grid) {
            $grid->event_id('ID');
            $grid->name(trans('game.event_name'));
            $grid->type(trans('game.type'))->display(function ($type) {
                switch ($type) {
                    case '1':
                        $type_name = trans('game.props');
                        break;
                    case '2':
                        $type_name = trans('game.exp');
                        break;
                    case '3':
                        $type_name = trans('game.game');
                        break;
                    default:
                        $type_name = trans('game.other');
                        break;
                }

                return $type_name;
            });
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Admin::form(StatEvent::class, function (Form $form) {
            $form->text('event_id', 'ID')->rules('required|numeric');
            $form->text('name', trans('game.event_name'))->rules('required');
            $form->radio('type', trans('game.type'))->options([1 => trans('game.props'), 2 => trans('game.exp'), 3 => trans('game.game')])->default(1);
        });
    }
}
